package multiplayer.lan;

import java.awt.event.MouseAdapter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Observable;
import java.util.Observer;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;

public class GuiLanClient extends JFrame implements Observer{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	DefaultListModel<ServerInfo> m= new DefaultListModel<ServerInfo>();
	JList<ServerInfo> ip= new JList<ServerInfo>(m);
	MouseAdapter ma;
	public GuiLanClient() {
		this.setSize(100,100);
		this.add(ip);
		this.setVisible(true);
		// TODO Auto-generated constructor stub
	}
	@Override
	public void update(Observable o, Object arg) {
		if(o instanceof ServersOnAir){
			ServersOnAir soa= (ServersOnAir) arg;
			loadServers(soa.getServers());
		}
	}
	public void loadServers(HashMap<String, ServerInfo> hashMap){
		m.removeAllElements();
		Iterator<String> it = hashMap.keySet().iterator();
		while(it.hasNext()){
			m.addElement(hashMap.get(it.next()));
		}
	}
	public void loadMouseAdapter(MouseAdapter ma){
		this.ma=ma;
		ip.addMouseListener(this.ma);
	}
}
